package com.ruoyi.project.other.cost.service.impl;

import com.ruoyi.common.utils.text.Convert;
import com.ruoyi.project.other.cost.domain.Cost;
import com.ruoyi.project.other.cost.domain.CostData;
import com.ruoyi.project.other.cost.mapper.CostMapper;
import com.ruoyi.project.other.cost.service.CostService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CostServiceImpl implements CostService {

    @Autowired
    private CostMapper costMapper;

    //多条件查询管理费
    @Override
    public List<Cost> findCost(Cost cost) {
        return costMapper.selectCost(cost);
    }

    /**
     * 查询数据条数和总金额
     * @return
     */
    @Override
    public CostData findData() {
        int count1 = 0;//应交金额
        int count2 = 0;//已缴金额

        Cost cost = new Cost();
        CostData costData = new CostData();
        List<Cost> costs1 = costMapper.selectCost(cost);
        costData.setRecordNum(costs1.size());

        for (Cost c : costs1) {
            int sum = c.getCostMoney() + c.getCostOverdue();
            count1 += sum;
        }

        cost.setCostPaystate(0);
        List<Cost> costs2 = costMapper.selectCost(cost);
        for (Cost c : costs2) {
            int sum = c.getCostMoney() + c.getCostOverdue();
            count2 += sum;
        }

        costData.setShouldNum(count1-count2);
        costData.setAlreadNum(count2);
        return costData;
    }

    /**
     * 删除管理费对象
     *
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteTCostByIds(String ids)
    {
        return costMapper.deleteTCostByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除管理费信息
     *
     * @param costId 管理费ID
     * @return 结果
     */
    @Override
    public int deleteTCostById(Integer costId)
    {
        return costMapper.deleteTCostById(costId);
    }

    /**
     * 通过主持人ID查询主持人信息
     * @param costHostid
     * @return
     */
    @Override
    public Cost findCostById(int costHostid) {
        return costMapper.selectCostById(costHostid);
    }

    /**
     * 修改管理费信息
     * @param cost
     * @return
     */
    @Override
    public int changeCost(Cost cost) {
        return costMapper.updateCost(cost);
    }

    /**
     * 查询免缴月份
     * @return
     */
    @Override
    public String findMjMonth() {
        String s = costMapper.selectMjMonth();
        //String[] split = s.split(",");
        return s;
    }
}
